import os
from time import sleep


class Flow(object):

    def __init__(self, package=None):
        self.cmd = "adb shell cat /proc/net/dev | grep  wlan0"
        self.package = package
        pass

    def Flow_data(self, time):
        wlan0_begin_Receive = round(
            int(os.popen(self.cmd).read().strip().split()[1]) / 1024 / 1024, 3)
        wlan0_begin_Transmit = round(
            int(os.popen(self.cmd).read().strip().split()[9]) / 1024 / 1024, 3)
        sleep(time)
        wlan0_end_Receive = round(
            int(os.popen(self.cmd).read().strip().split()[1]) / 1024 / 1024, 3)
        wlan0_end_Transmit = round(
            int(os.popen(self.cmd).read().strip().split()[9]) / 1024 / 1024, 3)
        return f"收：{round(wlan0_end_Receive - wlan0_begin_Receive, 3)}M,发：{round(wlan0_end_Transmit - wlan0_begin_Transmit, 3)}M" \
               f",总：{round(wlan0_end_Receive - wlan0_begin_Receive + wlan0_end_Transmit - wlan0_begin_Transmit, 3)}M"

    def Flow_data_base(self, package):
        pass


if __name__ == '__main__':
    print(Flow().Flow_data(10))
